<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="部门名称" prop="deptName">
        <el-input v-model="queryParams.deptName" placeholder="请输入部门名称" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" filterable placeholder="部门状态" clearable>
          <el-option v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.label"
                     :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['system:dept:add']">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">展开/折叠</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-if="refreshTable" v-loading="loading" :data="deptList" row-key="deptId"
              :default-expand-all="isExpandAll"
              :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
      <el-table-column prop="deptName" label="部门名称" width="260"></el-table-column>
      <el-table-column prop="orderNum" label="排序" width="80"></el-table-column>
      <el-table-column prop="status" label="状态" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column prop="pcUrl" label="pc域名" align="center">
      </el-table-column>
      <el-table-column prop="h5Url" label="h5域名" align="center">
      </el-table-column>
      <el-table-column prop="hospitalLogo" label="医院logo" align="center">
        <template slot-scope="scope">
          <img :src="getLogo(scope.row.hospitalLogo)" alt="" style="width: 40px;">
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="200">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['system:dept:edit']">修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-plus" @click="handleAdd(scope.row)"
                     v-if="getShowBtn(scope.row, 2)" v-hasPermi="['system:dept:add']">新增
          </el-button>
          <el-button v-if="scope.row.parentId != 0 && getShowBtn(scope.row, 3)" size="mini" type="text"
                     icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['system:dept:remove']">删除
          </el-button>
          <el-button size="mini" type="text" @click="getQrcode(scope.row)"
                     v-if="scope.row.deptId != 100">h5二维码
          </el-button>
          <!-- getShowBtn(scope.row, 2) && -->
          <!-- <el-button size="mini" type="text" @click="getFeituSetting(scope.row)" icon="el-icon-edit"
            v-if="getShowBtn(scope.row, 2) && scope.row.deptId != 100">霏图拍照仪设置</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加或修改部门对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="24" v-if="isShowUp">
            <el-form-item label="上级部门" prop="parentId">
              <treeselect :defaultExpandLevel="Infinity" @select="selectDept" v-model="form.parentId"
                          :disabled="isUpdateStatus" :options="deptOptions" :normalizer="normalizer"
                          placeholder="选择上级部门"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="部门名称" prop="deptName">
              <el-input v-model="form.deptName" placeholder="请输入部门名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="显示排序" prop="orderNum">
              <el-input-number v-model="form.orderNum" controls-position="right" :min="0"/>
            </el-form-item>
          </el-col>

        </el-row>


        <el-row>
          <el-col :span="12">
            <el-form-item label="负责人" prop="leader">
              <el-input v-model="form.leader" placeholder="请输入负责人" maxlength="20"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入联系电话" maxlength="11"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="邮箱" prop="email">
              <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="部门状态">

              <el-radio-group v-model="form.status">
                <el-radio v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.value">{{
                    dict.label
                  }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>

        </el-row>
        <div v-if="!isHosipital && isShowUp && isUpdateStatus">
          <el-row>
            <el-col :span="24">
              <el-form-item label-width="180px" label="捷医通开通科室组账号" prop="">
                <el-radio-group v-model="form.groupIdFlag" style="width:180px;">
                  <el-radio v-for="dict in sysAccountTypeArr0" :key="dict.value" :label="dict.value">{{
                      dict.label
                    }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
<!--          <el-row>-->
<!--            <el-col :span="24">-->
<!--              <el-button type="primary" plain icon="el-icon-plus" size="mini">添加HIS挂号门诊</el-button>-->

<!--              <div class="hisBox">-->
<!--                <el-table :data="hisTableData" border style="width: 100%">-->
<!--                  <el-table-column prop="date" label="日期" width="180"></el-table-column>-->
<!--                  <el-table-column prop="name" label="姓名" width="180"></el-table-column>-->
<!--                  <el-table-column prop="address" label="地址"></el-table-column>-->
<!--                </el-table>-->
<!--              </div>-->

<!--            </el-col>-->
<!--          </el-row>-->
          <el-row>
            <el-col :span="24">
              <el-form-item label="拍照设备" prop="">
                <el-select v-model="carmerSelectList" placeholder="门诊关联的拍照设备" filterable multiple style="width: 100%"
                           @change="saveCarmer" @focus="getsysCameraConfigListEvent">
                  <!--   @change="saveCarmer" -->
                  <el-option v-for="item in carmerList" :key="item.equipmentNumber"
                             :label="item.organizationName + '('+item.deviceName+')'"
                             :value="item.configId"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </div>


        <div v-if="isHosipital">

          <el-row>
            <el-col :span="12">
              <el-form-item label="医院性质" prop="nature">
                <el-select v-model="form.nature" filterable placeholder="请选择医院性质" clearable style="width: 100%">
                  <el-option v-for="dict in dict.type.sys_hospital_nature" :key="dict.value" :label="dict.label"
                             :value="dict.value"/>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="医院等级">
                <el-select v-model="form.level" filterable placeholder="请选择医院等级" clearable style="width: 100%">
                  <el-option v-for="dict in dict.type.sys_hospital_level" :key="dict.value" :label="dict.label"
                             :value="dict.value"/>
                </el-select>

              </el-form-item>
            </el-col>
          </el-row>


          <el-row>
            <el-col :span="24">
              <el-form-item label="医院地址" prop="area">
                <el-cascader v-model="form.area" placeholder="省,市,区" class="picker-form" :options="areaList" filterable
                             :props="{ children: 'childrenList', value: 'id', label: 'name' }" :clearable="true"
                             style="width: 100%">
                </el-cascader>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="具体地址" prop="address">
                <el-input v-model="form.address" placeholder="小区/乡村名称" style="width: 100%"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="pc域名" prop="pcUrl">
                <el-input v-model="form.pcUrl" placeholder="格式：https://hnsy.feitu.club/" style="width: 100%"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="h5域名" prop="h5Url">
                <el-input v-model="form.h5Url" placeholder="格式：https://hnsy-h5.feitu.club/"
                          style="width: 100%"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="安装系统" prop="sysVison">
                <el-select v-model="form.sysVison" filterable placeholder="请选择系统类型" clearable style="width: 100%">
                  <el-option v-for="dict in sysVisonArr" :key="dict.value" :label="dict.label" :value="dict.value"/>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="医院logo" prop="logo">
                <div>
                  <uploadPic @getUserAvatarUrl="updateHospitalLogo" :user="form" kind="0" :width="300" :height="300"
                             v-if="open"/>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="轮播图" prop="logo">
                <div>
                  <uploadMorePic @getBannerlist="updateBannerlist" :user="form" :width="750" :height="340" v-if="open"/>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="H5是否启用无身份证登记" prop="registrationIdCardFlag" label-width="200">
                <el-radio-group v-model="form.registrationIdCardFlag">
                  <el-radio v-for="dict in enableRegistrationIDArr" :key="dict.value" :label="dict.value">{{
                      dict.label
                    }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="AI分析报告是否显示黄褐斑评分" prop="aiStaticFlag" label-width="200">
                <el-radio-group v-model="form.aiStaticFlag">
                  <el-radio v-for="dict in enableAiStaticArr" :key="dict.value" :label="dict.value">{{
                      dict.label
                    }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="是否显示在小程序" prop="miniProgramShow" label-width="200">
                <el-radio-group v-model="form.miniProgramShow">
                  <el-radio v-for="dict in showMinArr" :key="dict.value" :label="dict.value">{{
                      dict.label
                    }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="form.miniProgramShow">
            <el-col :span="22" :offset="2">
              <el-card class="box-card">
                <div slot="header" class="clearfix">
                  <span>医生端小程序展示</span>
                </div>
                <div class="titleBox">
                  <span>首页显示</span>
                  <el-checkbox style="float: right; padding: 3px 0" :indeterminate="doctorIsIndeterminate"
                               v-model="doctorCheckAll"
                               @change="doctorHandleCheckAllChange">全选
                  </el-checkbox>
                </div>
                <div>
                  <el-checkbox-group v-model="doctorRoleMenusSelect" @change="doctorHandleCheckedChange">
                    <el-checkbox v-for="(item,index) in doctorRoleMenus" :key="index" :label="item">{{ item }}
                    </el-checkbox>
                  </el-checkbox-group>
                </div>
                <div class="titleBox">
                  <span>查看顾客详情</span>
                  <el-checkbox style="float: right; padding: 3px 0" :indeterminate="doctorViewIsIndeterminate"
                               v-model="doctorViewCheckAll"
                               @change="doctorViewHandleCheckAllChange">全选
                  </el-checkbox>
                </div>
                <div>
                  <el-checkbox-group v-model="doctorViewRoleMenusSelect" @change="doctorViewHandleCheckedChange">
                    <el-checkbox v-for="(item,index) in doctorViewRoleMenus" :key="index" :label="item">{{ item }}
                    </el-checkbox>
                  </el-checkbox-group>
                </div>

              </el-card>
            </el-col>
          </el-row>
          <el-row v-if="form.miniProgramShow">
            <el-col :span="22" :offset="2">
              <el-card class="box-card">
                <div slot="header" class="clearfix">
                  <span>顾客端小程序展示</span>
                </div>
                <div class="titleBox">
                  <span>首页显示</span>
                  <el-checkbox style="float: right; padding: 3px 0" :indeterminate="customerIsIndeterminate"
                               v-model="customerCheckAll"
                               @change="customerHandleCheckAllChange">全选
                  </el-checkbox>
                </div>
                <div>
                  <el-checkbox-group v-model="customerRoleMenusSelect" @change="customerHandleCheckedChange">
                    <el-checkbox v-for="(item,index) in customerRoleMenus" :key="index" :label="item">{{ item }}
                    </el-checkbox>
                  </el-checkbox-group>
                </div>
                <div class="titleBox">
                  <span>查看我的资料(必须要勾选"我的资料"才可查看)</span>
                  <el-checkbox style="float: right; padding: 3px 0" :indeterminate="customerViewIsIndeterminate"
                               v-model="customerViewCheckAll"
                               @change="customerViewHandleCheckAllChange">全选
                  </el-checkbox>
                </div>
                <div>
                  <el-checkbox-group v-model="customerViewRoleMenusSelect" @change="customerViewHandleCheckedChange">
                    <el-checkbox v-for="(item,index) in customerViewRoleMenus" :key="index" :label="item">{{ item }}
                    </el-checkbox>
                  </el-checkbox-group>
                </div>

              </el-card>
            </el-col>
          </el-row>
          <el-row v-if="form.miniProgramShow">
            <el-col :span="12">
              <el-form-item label="工作时间" prop="workingHours ">
                <el-input v-model.trim="form.workingHours " placeholder="请输入工作时间"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="form.miniProgramShow">
            <el-col :span="24">
              <el-form-item label="预约电话">
                <div class="appointmentPhoneBox">
                  <div v-for="(item,index) in appointmentPhoneList" :key="index" class="appointmentPhoneItem">
                    <div>
                      <div>
                        <el-input v-model.trim="item.appointmentPhone" placeholder="请输入预约电话" clearable
                                  style="width: 187px"/>
                      </div>
                      <div class="appointmentPhoneInput">
                        <el-input v-model.trim="item.appointmentAddress" placeholder="预约电话院区" clearable
                                  style="width: 187px"/>
                      </div>
                    </div>
                    <div v-if="appointmentPhoneList.length>1">
                      <el-button icon="el-icon-minus" circle @click="deleteAppointmentPhone(index)"></el-button>
                    </div>
                  </div>
                  <div>
                    <el-button icon="el-icon-plus" circle @click="addAppointmentPhone"></el-button>
                  </div>

                </div>

              </el-form-item>

            </el-col>


          </el-row>


          <el-row v-if="form.miniProgramShow == 1">
            <el-col :span="24">
              <el-form-item label="预约须知" prop="appointmentNotice">
                <WangEditor @change="changeWang" :value="form.appointmentNotice"></WangEditor>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="医院介绍" prop="introduce">
                <WangEditor @change="changeWangIntroduce" :value="form.introduce"></WangEditor>
                <!-- <el-input v-model="form.introduce" type="textarea" :rows="3" placeholder="请输入介绍" style="width:460px;"></el-input> -->
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="APPId" prop="appId">
                <el-input v-model="form.APPId" placeholder="appId" style="width: 100%"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="secretKey" prop="secretKey">
                <el-input v-model="form.secretKey" placeholder="secretKey" style="width: 100%"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div v-if="!isHosipital">
          <el-row>
            <el-col :span="24">
              <el-form-item label="门诊介绍" prop="introduce">
                <!-- <el-input v-model="form.introduce" type="textarea" :rows="3" placeholder="请输入介绍"
                  style="width:460px;"></el-input> -->
                <WangEditor @change="changeWangIntroduce" :value="form.introduce"></WangEditor>
              </el-form-item>
            </el-col>
          </el-row>
        </div>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="qrCodeTitle" :visible.sync="qrCodeOpen" @close="closeQrCodeDialog" width="600px" append-to-body>
      <div class="h5-url-text">
        <div>{{ urlText }}</div>
      </div>
      <div class="h5-poster" id="h5Poster">
        <img :src="hospitalLogo" alt="" class="hospital-logo">
        <span class="hospital-name">{{ hospitalName }}</span>
        <span class="hospital-name0" v-if="hospitaldeptName">——{{ hospitaldeptName }}</span>
        <img :src="h5PosterBgImg" alt="" class="bg-img">
        <div v-if="qrCodeOpen" class="qrcode" ref="qrCodeDiv"></div>
      </div>
      <div class="h5-url-text">
        <el-button type="primary" size="mini" @click="downloadPosterImg">下 载</el-button>
      </div>
    </el-dialog>
    <!-- 拍照仪管理 -->


  </div>
</template>

<script>
import html2canvas from 'html2canvas'
import QRCode from 'qrcodejs2'
import {mapGetters} from "vuex";
import {listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild} from "@/api/system/dept";
import {getsysCameraConfigList, updatesysCameraConfigInfo, listCameraConfig} from "@/api/cameraSetting/cameraSetting";
import uploadPic from "@/views/components/uploadImage/uploadPic.vue";
import uploadMorePic from "@/views/components/uploadImage/uploadMorePic.vue";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {addressJson} from "@/api/patients/personal";
import WangEditor from "@/views/components/WangEditor";

export default {
  name: "Dept",
  dicts: ['sys_normal_disable', 'sys_hospital_level', 'sys_hospital_nature'],
  components: {Treeselect, uploadPic, uploadMorePic, WangEditor},
  data() {
    return {
      carmerList: [],
      carmerSelectList: [],
      isShowUp: true,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 表格树数据
      deptList: [],
      // 部门树选项
      deptOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 是否时修改
      isUpdateStatus: false,// 默认新增  true  修改
      // 查询参数
      queryParams: {
        deptName: undefined,
        status: undefined
      },
      sysVisonArr: [
        {label: 'SCDD专病版（SAAS）', value: '1'},
        {label: '全流程(SAAS)', value: '2'},
        {label: '全流程（院内版）', value: '3'}
      ],
      showMinArr: [
        {label: '否', value: 0},
        {label: '是', value: 1},
      ],
      enableRegistrationIDArr: [
        {label: '不启用', value: 0},
        {label: '启用', value: 1},
      ],
      enableAiStaticArr:[ {label: '不显示', value: 0},
      {label: '显示', value: 1},],
      isHosipital: false,
      // 省市区
      areaList: [],
      // 医生和顾客角色菜单

      doctorRoleMenus: ['顾客管理', '医生咨询', '消息', '我的报表', '科室报表', '今日动态', '专病分析', '顾客分析', '医院介绍', '专家介绍', '宣教公告'],
      doctorRoleMenusSelect: [],
      doctorCheckAll: false,
      doctorIsIndeterminate: true,
      doctorViewRoleMenus: ['简况', '顾客画像', '照片', '趋势', '问诊', '随访', '方案', '治疗', '治疗照片', '检测指标'],
      doctorViewRoleMenusSelect: [],
      doctorViewCheckAll: false,
      doctorViewIsIndeterminate: true,
      customerRoleMenus: ['我的预约', '我的资料', '我的顾客码', '我的随访', '温馨提示', '个人信息', '我的医生', '治疗预约', '登记', '签到', '医生咨询', '消息', '医院介绍', '专家介绍', '宣教公告', '预约电话和工作时间', '照片上传'],
      customerRoleMenusSelect: [],
      customerCheckAll: false,
      customerIsIndeterminate: true,
      customerViewRoleMenus: ['简况', '顾客画像', '照片', '趋势', '问诊', '随访', '方案', '治疗', '治疗照片', '检测指标'],
      customerViewRoleMenusSelect: [],
      customerViewCheckAll: false,
      customerViewIsIndeterminate: true,
      appointmentPhoneList: [{  //预约电话列表
        appointmentPhone: '',
        appointmentAddress: ''
      }],
      // 表单参数
      form: {
        nature: undefined,//医院性质
        level: undefined,//等级
        area: undefined,//省市区
        address: undefined,//详细地址
        sysVison: undefined,//安装系统
        appId: undefined,//APPId
        secretKey: undefined,//secretKey
        provinceId: undefined,
        cityId: undefined,
        countyId: undefined,
        avatar: undefined,
        logo: undefined,
        hospitalLogo: undefined,
        rotationChart: undefined,
        jumpAddress: undefined,
        introduce: '',
        miniProgramShow: 0,
        registrationIdCardFlag: 0,//0 不启用  1  启用
        doctorRoleMenusSelect: '',
        doctorViewRoleMenusSelect: '',
        customerRoleMenusSelect: '',
        customerViewRoleMenusSelect: '',
        appointmentPhoneList: '',   ////预约电话列表
        workingHours: '',   //工作时间
        groupIdFlag: 0, // 0关闭科室组账号 1 打开科室组账号

      },

      // 表单校验
      rules: {
        parentId: [
          {required: true, message: "上级部门不能为空", trigger: "blur"}
        ],
        deptName: [
          {required: true, message: "部门名称不能为空", trigger: "blur"}
        ],
        orderNum: [
          {required: true, message: "显示排序不能为空", trigger: "blur"}
        ],
        email: [
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"]
          }
        ],
        phone: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ]
      },
      h5PosterBgImg: require('@/assets/images/h5.jpg'),
      qrCodeTitle: '',
      qrCodeOpen: false,
      urlText: '',
      hospitalName: '',
      hospitalLogo: '',
      hospitaldeptName: '',
      sysAccountTypeArr0: [
        {label: '否', value: 0},
        {label: '是', value: 1}
      ],
      hisTableData: [],


    };
  },
  created() {
    this.getList();
    this.getAddressData()

  },
  computed: {
    ...mapGetters(["dept", "hospital"]),
  },
  methods: {
    addAppointmentPhone() {
      if (this.appointmentPhoneList[this.appointmentPhoneList.length - 1].appointmentPhone) {
        this.appointmentPhoneList.push({
          appointmentPhone: '',
          appointmentAddress: ''
        })
      } else {
        this.$modal.msgWarning("请输入预约电话");
      }

    },
    deleteAppointmentPhone(index) {
      this.$confirm('请确认删除该项?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.appointmentPhoneList.splice(index, 1)
      }).catch(() => {

      });

    },
    doctorHandleCheckAllChange(val) {
      console.log(val)
      this.doctorRoleMenusSelect = val ? this.doctorRoleMenus : [];
      this.doctorIsIndeterminate = false;
    },
    doctorHandleCheckedChange(value) {
      console.log('value---', value)
      console.log(value['医生咨询'])
      if (value['医生咨询']) {
        console.log('你好')
      } else {
        console.log('不好--')
      }
      let checkedCount = value.length;
      this.doctorCheckAll = checkedCount === this.doctorRoleMenus.length;
      this.doctorIsIndeterminate = checkedCount > 0 && checkedCount < this.doctorRoleMenus.length;
    },
    doctorViewHandleCheckAllChange(val) {
      this.doctorViewRoleMenusSelect = val ? this.doctorViewRoleMenus : [];
      this.doctorViewIsIndeterminate = false;
    },
    doctorViewHandleCheckedChange(value) {
      let checkedCount = value.length;
      this.doctorViewCheckAll = checkedCount === this.doctorViewRoleMenus.length;
      this.doctorViewIsIndeterminate = checkedCount > 0 && checkedCount < this.doctorViewRoleMenus.length;
    },
    customerHandleCheckAllChange(val) {
      console.log(val)
      this.customerRoleMenusSelect = val ? this.customerRoleMenus : [];
      this.customerIsIndeterminate = false;
    },
    customerHandleCheckedChange(value) {
      let checkedCount = value.length;
      this.customerCheckAll = checkedCount === this.customerRoleMenus.length;
      this.customerIsIndeterminate = checkedCount > 0 && checkedCount < this.customerRoleMenus.length;
    },
    customerViewHandleCheckAllChange(val) {
      console.log(val)
      this.customerViewRoleMenusSelect = val ? this.customerViewRoleMenus : [];
      this.customerViewIsIndeterminate = false;
    },
    customerViewHandleCheckedChange(value) {
      let checkedCount = value.length;
      this.customerViewCheckAll = checkedCount === this.customerViewRoleMenus.length;
      this.customerViewIsIndeterminate = checkedCount > 0 && checkedCount < this.customerViewRoleMenus.length;
    },
    getlistCameraConfig() {
      let formData = this.form
      let carmerSelectListarray = []
      let params = {
        pageNum: 1,
        pageSize: 999,
        deptId: formData.deptId,
        hospitalId: formData.parentId
      }
      listCameraConfig(params).then((response) => {
          if (response.code == 200) {
            let data = response.rows
            if (data) {
              data.forEach(function (element1) {
                carmerSelectListarray.push(element1.configId)
              })
              this.carmerSelectList = carmerSelectListarray
            } else {
              this.carmerSelectList = []
            }
            this.open = true;
            this.title = "修改部门";
          }
        }
      );
    },
    getsysCameraConfigListEvent() {
      let formData = this.form
      let params = {
        deptId: formData.deptId,
        hospitalId: formData.parentId
      }
      getsysCameraConfigList(params).then(response => {
        let data = response.data
        // console.log(data)
        this.carmerList = data
      });
    },
    saveCarmer() {//  保存
      console.log(this.form)
      let formData = this.form
      let params = []
      if (this.carmerSelectList && this.carmerSelectList.length > 0) {
        this.carmerSelectList.forEach(function (element1) {
          let obj = {
            configId: element1,
            deptId: formData.deptId,
            hospitalId: formData.parentId
          }
          params.push(obj)
        })
      } else {
        let obj = {
          configId: '',
          deptId: formData.deptId,
          hospitalId: formData.parentId
        }
        params.push(obj)
      }

      updatesysCameraConfigInfo(params).then(response => {
        console.log("保存接口~")
        this.$modal.msgSuccess("关联成功");
      });


    },
    downloadPosterImg() {
      html2canvas(
        document.getElementById('h5Poster'),
        {
          backgroundColor: null,//画出来的图片有白色的边框,不要可设置背景为透明色（null）
          useCORS: true,//支持图片跨域
          scale: 1,//设置放大的倍数
        }
      ).then(canvas => {
        //截图用img元素承装，显示在页面的上
        // let img = new Image();
        // img.src = canvas.toDataURL('image/jpeg');
        // document.getElementById('test').appendChild(img);

        //如果你需要下载截图，可以使用a标签进行下载
        let a = document.createElement('a');
        a.href = canvas.toDataURL('image/jpeg');// toDataURL :图片格式转成 base64
        a.download = 'poster';
        a.click();
      })

    },
    changeWang(html) {//富文本
      //这里的html是带有标签的
      this.form.appointmentNotice = html
      // console.log(this.form.content)
    },
    changeWangIntroduce(html) {
      this.form.introduce = html
    },
    getLogo(url) {
      return process.env.VUE_APP_BASE_API + url
    },
    /** 医院logo图修改返回的地址更新到form */
    updateHospitalLogo(logoUrl) {
      console.log('updateHospitalLogo', logoUrl)
      if (logoUrl.kind == 0) {
        this.form.hospitalLogo = logoUrl.imgUrl;
      }
      // else if (logoUrl.kind == 1) {
      //   this.form.rotationChart = logoUrl.imgUrl;
      //   this.form.jumpAddress=logoUrl.jumpAddress
      // }
    },
    updateBannerlist(data) {

      let bannerUrl = data.bannerUrl
      let bannerUrlStr = ''
      bannerUrl.forEach((it, index) => {
        if (index == bannerUrl.length - 1) {
          bannerUrlStr = bannerUrlStr + it
        } else {
          bannerUrlStr = bannerUrlStr + it + ","
        }

      })
      this.form.jumpAddress = bannerUrlStr
      console.log(bannerUrlStr)
      this.form.rotationChart = data.bannerList.join(',')
    },
    bindQRCode() {
      this.$nextTick(() => {
        new QRCode(this.$refs.qrCodeDiv, {
          text: this.urlText,//url地址  文本等需要转换为二维码的内容
          width: 110,
          height: 110,
          colorDark: "#00857e", //二维码颜色
          colorLight: "#ffffff", //二维码背景色
          correctLevel: QRCode.CorrectLevel.L, //容错率，L/M/H
        });
      });
    },
    // 获取地区
    getAddressData() {
      addressJson().then((res) => {
        this.areaList = res.data;
      });
    },

    selectDept(e, type) {
      console.log(e)
      if (type == 2) {
        if (e.ancestors && this.getSplit(e.ancestors).length == 2) {
          this.isHosipital = true
        } else {
          this.isHosipital = false
        }
      } else {
        if (e.ancestors && this.getSplit(e.ancestors).length == 1) {
          this.isHosipital = true
        } else {
          this.isHosipital = false
        }
      }

    },
    getSplit(str) {
      return str.split(',')
    },
    getShowBtn(item, type) {//1 修改 2 新增 3删除
      let btnStatus = true
      let that = this
      if (that.getSplit(that.dept.ancestors).length == 2) {//2级医院 不能删除本级 且不能新增第三级 医院级
        if (that.getSplit(item.ancestors).length == 2) {
          if (type == 2) {
            btnStatus = true
          } else {
            btnStatus = false
          }
        } else if (that.getSplit(item.ancestors).length == 3) {
          if (type == 2) {
            btnStatus = false
          } else {
            btnStatus = true
          }
        }
      }
      if (that.getSplit(that.dept.ancestors).length == 1) {//1 不能删除本级 且不能新增第三级 平台级
        if (that.getSplit(item.ancestors).length == 3) {
          if (type == 2) {
            btnStatus = false
          } else {
            btnStatus = true
          }
        }
      }
      return btnStatus
    },
    /** 查询部门列表 */
    getList() {
      this.loading = true;
      let that = this
      listDept(this.queryParams).then(response => {
        let data = this.handleTree(response.data, "deptId");
        console.log("ooooooooooo//////////////////////////")
        console.log(data)
        if (that.getSplit(that.dept.ancestors).length == 1) { //平台级
          data.forEach(function (element) {
            let data1 = element.children
            if (data1) { //第二级 医院
              data1.forEach(function (element1) {
                let data2 = element1.children
                if (data2) {//第三级门诊
                  data2.forEach(function (element2) {
                    element2.h5Url = element1.h5Url
                    element2.pcUrl = element1.pcUrl
                    element2.parentName = element1.deptName
                  })
                }
              })
            }


          });
        } else {
          data.forEach(function (element) {
            let data1 = element.children
            if (data1) { //第二级 医院
              data1.forEach(function (element1) {
                element1.h5Url = element.h5Url
                element1.pcUrl = element.pcUrl
                element1.parentName = element.deptName
              })
            }
          });
        }

        this.deptList = data
        this.loading = false;
      });
    },
    /** 转换部门数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.deptId,
        label: node.deptName,
        children: node.children
      };
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        deptId: undefined,
        parentId: undefined,
        deptName: undefined,
        orderNum: undefined,
        leader: undefined,
        phone: undefined,
        email: undefined,
        status: "0",
        nature: undefined,//医院性质
        level: undefined,//等级
        area: undefined,//省市区
        provinceId: undefined,
        cityId: undefined,
        countyId: undefined,
        address: undefined,//详细地址
        sysVison: undefined,//安装系统
        appId: undefined,//APPId
        secretKey: undefined,//secretKey
        avatar: undefined,
        hospitalLogo: undefined,
        rotationChart: undefined,
        jumpAddress: undefined,
        introduce: '',
        miniProgramShow: 0,
        registrationIdCardFlag: 0,//0 不启用  1  启用
        doctorRoleMenusSelect: '',
        doctorViewRoleMenusSelect: '',
        customerRoleMenusSelect: '',
        customerViewRoleMenusSelect: '',
        appointmentPhoneList: '',
        workingHours: '',
        groupIdFlag: 0, // 0关闭科室组账号 1 打开科室组账号
      };
      this.isHosipital = false
      this.doctorRoleMenusSelect = []
      this.doctorViewRoleMenusSelect = []
      this.customerRoleMenusSelect = []
      this.customerViewRoleMenusSelect = []
      this.appointmentPhoneList = [{  //预约电话列表
        appointmentPhone: '',
        appointmentAddress: ''
      }]
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset();
      this.isShowUp = true
      this.isUpdateStatus = false
      console.log(row)
      if (row != undefined && row != null) {
        this.selectDept(row)
        this.form.parentId = row.deptId;
      }
      this.open = true;
      this.title = "添加部门";
      let that = this

      listDept().then(response => {
        let data = response.data
        let dataArr = []
        if (that.getSplit(that.dept.ancestors).length == 2) {//2级医院 不能删除本级 且不能新增第三级 医院级 只显示2

          if (data && data.length > 0) {
            data.forEach(function (ele) {
              if (that.getSplit(ele.ancestors).length == 2) {
                dataArr.push(ele)
              }
            })
          }
        }
        if (that.getSplit(that.dept.ancestors).length == 1) {//1 不能删除本级 且不能新增第三级 平台级显示医院 1 2
          if (data && data.length > 0) {
            data.forEach(function (ele) {
              if (that.getSplit(ele.ancestors).length == 2 || that.getSplit(ele.ancestors).length == 1) {
                dataArr.push(ele)
              }
            })
          }
        }
        this.deptOptions = this.handleTree(dataArr, "deptId");
      });
    },
    /** 展开/折叠操作 */
    toggleExpandAll() {
      this.refreshTable = false;
      this.isExpandAll = !this.isExpandAll;
      this.$nextTick(() => {
        this.refreshTable = true;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      if (this.getShowBtn(row, 3)) {
        this.isShowUp = true
      } else {
        this.isShowUp = false
      }
      this.isUpdateStatus = true
      this.reset();
      this.selectDept(row, 2)
      getDept(row.deptId).then(response => {
        this.form = response.data;
        this.form.avatar = response.data.hospitalLogo;

        if (this.form.doctorRoleMenusSelect) {
          this.doctorRoleMenusSelect = this.form.doctorRoleMenusSelect.split(',')
        } else {
          this.doctorRoleMenusSelect = []
        }
        if (this.form.doctorViewRoleMenusSelect) {
          this.doctorViewRoleMenusSelect = this.form.doctorViewRoleMenusSelect.split(',')
        } else {
          this.doctorViewRoleMenusSelect = []
        }
        if (this.form.customerRoleMenusSelect) {
          this.customerRoleMenusSelect = this.form.customerRoleMenusSelect.split(',')
        } else {
          this.customerRoleMenusSelect = []
        }
        if (this.form.customerViewRoleMenusSelect) {
          this.customerViewRoleMenusSelect = this.form.customerViewRoleMenusSelect.split(',')
        } else {
          this.customerViewRoleMenusSelect = []
        }
        if (this.form.registrationIdCardFlag) {

        } else {
          this.form.registrationIdCardFlag = 0
        }

        if (this.form.appointmentPhoneList && JSON.parse(this.form.appointmentPhoneList).length > 0) {
          this.appointmentPhoneList = JSON.parse(this.form.appointmentPhoneList)
        } else {
          this.appointmentPhoneList = [{
            appointmentPhone: '',
            appointmentAddress: ''
          }]
        }

        if (response.data.rotationChart) {
          this.form.banner = response.data.rotationChart.split(',');
        }
        if (response.data.jumpAddress) {
          this.form.bannerUrl = response.data.jumpAddress.split(',');
        } else {
          this.form.bannerUrl = []
        }

        if (this.form.parentId == 0) {
          this.isShowUp = false
        }
        this.form.area = [
          Number(response.data.provinceId),
          Number(response.data.cityId),
          Number(response.data.countyId),
        ];
        if (this.form.parentId && this.form.parentId != 100) {
          this.getsysCameraConfigListEvent()
          this.getlistCameraConfig()

        } else {
          this.open = true;
          this.title = "修改部门";
        }
        // if (this.form.feituCameraStatus == undefined || this.form.feituCameraStatus == null || this.form.feituCameraStatus == '') {
        //   this.form.feituCameraStatus = 0
        // }


      });
      listDeptExcludeChild(row.deptId).then(response => {
        this.deptOptions = this.handleTree(response.data, "deptId");
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      console.log('submitForm=========', this.form)
      this.$refs["form"].validate(valid => {
        if (!!this.form.area) {
          this.form.provinceId = String(this.form.area[0]);
          this.form.cityId = String(this.form.area[1]);
          this.form.countyId = String(this.form.area[2]);
        }
        this.form.doctorRoleMenusSelect = this.doctorRoleMenusSelect.join(',')
        this.form.doctorViewRoleMenusSelect = this.doctorViewRoleMenusSelect.join(',')
        this.form.customerRoleMenusSelect = this.customerRoleMenusSelect.join(',')
        this.form.customerViewRoleMenusSelect = this.customerViewRoleMenusSelect.join(',')
        this.appointmentPhoneList = this.appointmentPhoneList.filter(item => {
          return item.appointmentPhone !== ''
        })
        if (this.appointmentPhoneList.length > 0) {
          this.form.appointmentPhoneList = JSON.stringify(this.appointmentPhoneList)
        } else {
          this.form.appointmentPhoneList = ''
        }

        if (valid) {
          if (this.form.deptId != undefined) {
            updateDept(this.form).then(response => {
              if (response.code == 200) {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }

            });
          } else {
            addDept(this.form).then(response => {
              if (response.code == 200) {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();

              }

            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除名称为"' + row.deptName + '"的数据项？').then(function () {
        return delDept(row.deptId);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    getQrcode(row) {
      console.log("row九点九九九 就就就")
      console.log(row)
      console.log("---------------------------------------")
      if (row.h5Url) {
        if (row.parentName) { //门诊
          this.hospitalName = row.parentName
          this.hospitaldeptName = row.deptName
          this.hospitalLogo = process.env.VUE_APP_BASE_API + row.hospitalLogo
          this.qrCodeTitle = row.parentName + row.deptName + 'h5二维码'
          this.qrCodeOpen = true
          this.urlText = `${row.h5Url}/subPackages/remind/medicalInfo/index?deptId=` + row.deptId
        } else {//医院
          this.hospitalName = row.deptName
          this.hospitaldeptName = ''
          this.hospitalLogo = process.env.VUE_APP_BASE_API + row.hospitalLogo
          this.qrCodeTitle = row.deptName + 'h5二维码'
          this.qrCodeOpen = true
          this.urlText = `${row.h5Url}/subPackages/remind/medicalInfo/index`
        }

        this.bindQRCode()
      } else {
        this.$message.warning(row.deptName + '没有h5域名，请添加后在生成h5二维码')
      }
    },

    closeQrCodeDialog() {
      this.qrCodeOpen = false
      this.urlText = ''
    }
  }
};
</script>
<style scoped lang="scss">
::v-deep .el-dialog:not(.is-fullscreen) {
  margin-top: 10px !important;
}

.qrcode {
  position: absolute;
  right: 40px;
  bottom: 45px;
}


.hospital-logo {
  position: absolute;
  right: 20px;
  top: 20px;
  display: block;
  width: 40px;
}

.hospital-name {
  position: absolute;
  left: 20px;
  top: 20px;
  display: block;
  font-size: 18px;
  font-weight: bold;
  color: #008182;
}

.hospital-name0 {
  position: absolute;
  left: 50px;
  top: 45px;
  display: block;
  font-size: 14px;
  font-weight: bold;
  color: #008182;
}

.h5-poster {
  position: relative;
  width: 360px;
  margin: 0 auto;
}

.h5-poster .bg-img {
  display: block;
  width: 360px;
  margin: 0 auto;
}

.h5-url-text {
  margin: 20px;
  text-align: center;
}

.box-card {
  margin-bottom: 10px;

  .titleBox {
    margin: 10px 0;
    padding-bottom: 5px;
    border-bottom: 1px solid #e6ebf5;
    font-weight: bold;
  }
}

.appointmentPhoneBox {
  display: flex;
  flex-wrap: wrap;
  align-items: center;

  .appointmentPhoneItem {
    display: flex;
    align-items: center;
    margin-right: 10px;

    .appointmentPhoneInput {
      margin: 6px 0;

    }
  }

}

.hisBox {
  margin: 10px 0;
}

</style>
